<template>
  <div class="padding-lr">
    <div class="text-right">
      <el-button type="success" size="mini" @click="save"> 保存 </el-button>
    </div>
    <el-row :gutter="10" class="margin-top">
      <el-col :span="2"> 有效期至: </el-col>
      <el-col :span="20">
        <el-input
          v-model="validDate"
          :rows="5"
          size="mini"
          type="text"
          :readonly="true"
          clearable
        />
      </el-col>
    </el-row>
    <el-row :gutter="10" class="margin-top">
      <el-col :span="2"> 申请原因: </el-col>
      <el-col :span="20">
        <el-input v-model="reason" :rows="5" size="mini" clearable />
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { ajax } from "@/store/yg/common/utils";
import Row from "../../../../yg/layout/main/page/wrapper/form/Row";
import { closeDialog } from "@/utils";

export default {
  components: { Row },
  data() {
    return {
      reason: "",
      validDate: "",
    };
  },
  mounted() {
    let n = -31;
    let d = (d = new Date());
    let year = d.getFullYear();
    let mon = d.getMonth() + 1;
    let day = d.getDate();
    if (day <= n) {
      if (mon > 1) {
        mon = mon - 1;
      } else {
        year = year - 1;
        mon = 12;
      }
    }
    d.setDate(d.getDate() - n);
    year = d.getFullYear();
    mon = d.getMonth() + 1;
    day = d.getDate();
    this.validDate =
      year +
      "-" +
      (mon < 10 ? "0" + mon : mon) +
      "-" +
      (day < 10 ? "0" + day : day);
  },
  methods: {
    async save() {
      ajax(
        "postponeInHighSeas",
        {
          ids: this.$store.state.edit.ids,
          validDate: this.validDate,
          reason: this.reason,
        },
        {
          class: "com.tofba.app.client.customer.CustomerInfoClient",
        }
      ).then(
        (res) => {
          if (res.code == 200) {
            this.$message.success("保存成功");
            closeDialog();
            location.reload();
          } else {
            this.$message.error("保存失败:" + res.message);
          }
        },
        (error) => {
          console.log(error);
        }
      );
    },
  },
};
</script>

<style scoped>
/deep/ .el-select {
  width: 100%;
}
.btn-group {
  float: right;
}
</style>
